package com.mayikt.service.impl;

import com.mayikt.ProductDetailService;
import com.mayikt.base.BaseApiService;
import com.mayikt.base.BaseResponse;
import com.mayikt.es.entity.ProductEntity;
import com.mayikt.es.reposiory.ProductReposiory;
import com.mayikt.resp.dto.ProductDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

@RestController
public class ProductDetailServiceImpl extends BaseApiService implements ProductDetailService {
    @Autowired
    private ProductReposiory productReposiory;

    @Override
    public BaseResponse<ProductDto> getProductsearchDetails(Long productId) {
        Optional<ProductEntity> optionalResult = productReposiory.findById(productId);
        ProductEntity productEntity = optionalResult.get();
        if (productEntity == null) {
            return setResultError("没有查询到数据");
        }
        ProductDto productDto = doToDto(productEntity, ProductDto.class);
        return setResultSuccess(productDto);
    }
}
